# -*- coding:utf-8 -*-

__author__ = 'chendaqing'

'''
团购模块的view函数
'''

from flask import Blueprint, render_template, session, redirect, \
    url_for, request, flash, g, jsonify, abort
from mark.helpers import request_wants_json, get_city

tuangou = Blueprint('tuangou', __name__)


@tuangou.route('/')
def index():
	if request_wants_json():
		pass
		#return jsonify(tjson=[r.to_json for r in tjson])
	req_ip = request.remote_addr
	city = get_city(req_ip) # 根据IP地址获取城市名称
	print req_ip
	print request.path
	return render_template('t/index.html', city = city)

@tuangou.route('/deals')
def deals():
	# 往期团购的显示
	if request_wants_json():
		pass
	req_ip = request.remote_addr
	city = get_city(req_ip)

	return render_template('t/deals.html', city = city)

@tuangou.route('/deals/<int:pageNo>')
def deals_detail(pageNo):
    """
        处理类似/deal/508511.html的页面
    """
    pass
    
    
@tuangou.route('/help/faq')
def help_faq():
	# 常见问题
	pass

@tuangou.route('/help/newbie')
def help_newbie():
	# 新手指南
	pass

@tuangou.route('/help/tutorial')
def help_tutorial():
	# 入门教程
	pass

@tuangou.route('/changecity')
def change_city():
    #切换城市
    pass
    
@tuangou.route('/category/<category_name>')
@tuangou.route('/category/<category_name>/<order>')
def category(category, order=None):
    """
    处理类似以下的URI：
    /category/new/
    /category/new/discount
    /category/food/
    /category/entertainment/
    /category/life/
    /category/online/
    /category/dreams/
    /category/all/hot
    """
    # 分类/user/<username>/
    pass


@tuangou.route('/score')
def go_score_shop():
    # 跳转到积分商城
    # redirect(url_for("post.view", post_id=post_id))
    # 跟上其他模块的函数名称
    print request.path
    return redirect(url_for('score.score_index'))
    
if __name__ == "__main__":
	index()